package com.example.hearthstoneagain;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.os.Build;

public class CartaActivity extends ActionBarActivity {

	String nome, textocarta, comentario, url;
	int attack, health, custo;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle extras = getIntent().getExtras();
		
		nome = extras.getString("nome");
		if(nome.equals("bobeira")) {
			bobeira();
			return;
		}
		textocarta = extras.getString("textocarta");
		attack = extras.getInt("attack");
		health = extras.getInt("health");
		custo = extras.getInt("custo");
		String tipo = extras.getString("tipo");
		comentario = extras.getString("comentario");
		url = extras.getString("url");
		
		switch(tipo) {
			case "Minion" :
				criaMinion();
				break;
			case "Spell" :
				criaSpell();
				break;
			case "Weapon" :
				criaWeapon();
				break;
			default :
				criaMinion();
		
		}
		
	}
	
	private void bobeira() {
		setContentView(R.layout.minion_layout);

		TextView txtview = (TextView) this.findViewById(R.id.minion2);
		
		txtview.setText("Chinelo");
		
		txtview = (TextView) this.findViewById(R.id.minion4);
		
		txtview.setText("Battlecry: A bobeira comeca.");
		
		txtview = (TextView) this.findViewById(R.id.minion6);
		
		txtview.setText(new Integer(99).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion8);
		
		txtview.setText(new Integer(99).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion10);
		
		txtview.setText(new Integer(-1).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion11);
		
		txtview.setText("");
		
		DownloadImageTask t = new DownloadImageTask((ImageView) findViewById(R.id.minionimg));
		t.execute("http://i.imgur.com/vQMuzx5.png");
	}

	private void criaMinion() {
		setContentView(R.layout.minion_layout);
		
		TextView txtview = (TextView) this.findViewById(R.id.minion2);
		
		txtview.setText(nome);
		
		txtview = (TextView) this.findViewById(R.id.minion4);
		
		txtview.setText(textocarta);
		
		txtview = (TextView) this.findViewById(R.id.minion6);
		
		txtview.setText(new Integer(attack).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion8);
		
		txtview.setText(new Integer(health).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion10);
		
		txtview.setText(new Integer(custo).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion11);
		
		if(comentario.equals("")) {
			txtview.setText("");
		}
		else {
			txtview.setText(txtview.getText()+comentario);
		}
		
		DownloadImageTask t = new DownloadImageTask((ImageView) findViewById(R.id.minionimg));
		t.execute(url);
		
	}
	
	private void criaSpell() {
		setContentView(R.layout.spell_layout);
		
		TextView txtview = (TextView) this.findViewById(R.id.spell2);
		
		txtview.setText(nome);
		
		txtview = (TextView) this.findViewById(R.id.spell4);
		
		txtview.setText(textocarta);
		
		txtview = (TextView) this.findViewById(R.id.spell6);
		
		txtview.setText(new Integer(custo).toString());
		
		txtview = (TextView) this.findViewById(R.id.spell7);
		
		if(comentario.equals("")) {
			txtview.setText("");
		}
		else {
			txtview.setText(txtview.getText()+comentario);
		}
		
		DownloadImageTask t = new DownloadImageTask((ImageView) findViewById(R.id.spellimg));
		t.execute(url);
		
	}
	
	private void criaWeapon() {
		setContentView(R.layout.minion_layout);
		
		TextView txtview = (TextView) this.findViewById(R.id.minion2);
		
		txtview.setText(nome);
		
		txtview = (TextView) this.findViewById(R.id.minion4);
		
		txtview.setText(textocarta);
		
		txtview = (TextView) this.findViewById(R.id.minion6);
		
		txtview.setText(new Integer(attack).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion7);
		
		txtview.setText("Durability:");
		
		txtview = (TextView) this.findViewById(R.id.minion8);
		
		txtview.setText(new Integer(health).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion10);
		
		txtview.setText(new Integer(custo).toString());
		
		txtview = (TextView) this.findViewById(R.id.minion11);
		
		if(comentario.equals("")) {
			txtview.setText("");
		}
		else {
			txtview.setText(txtview.getText()+comentario);
		}
		
		DownloadImageTask t = new DownloadImageTask((ImageView) findViewById(R.id.minionimg));
		t.execute(url);
		
	}
	
}
